package YAPserver.behaviours;

import YAPserver.collisionEngine.*;
import YAPserver.gameObjects.Slider;
import YAPserver.gameObjects.GameWall;
/**
 * This class is a special type of bounce implementing BounceBehaviour directly.
 * This is invoked by the BounceToPlayer mod.
 * A ball bouncing from a slider has a dynamic bounce and one from a wall has a
 * mirror bounce. Every time a ball hits one of these mentioned objects (slider or wall) its
 * speed is set to m_speed, a constant speed set when this class is constructed.
 * @author Daniel
 *
 */
public class BounceFromPlayer implements BounceBehaviour{
	BounceBehaviour m_sliderBounce;
	BounceBehaviour m_wallBounce;
	double m_speed;
	/**
	 * Constructs a BounceBehaviour with a constant speed which a ball is set to
	 * every time it hits an object with this behaviour.
	 * @param ballSpeed double speed to which all ballAbstracts are set when they hit a gameObject that belongs to a specified player
	 */
	public BounceFromPlayer(double ballSpeed){
		m_sliderBounce = new BounceDynamic();
		m_wallBounce = new BounceMirror();
		m_speed = ballSpeed;
	}
	@Override
	public void bounce(Ball ball, Wall wall) {
		ball.setSpeed(m_speed);
		if(wall instanceof Slider){
			m_sliderBounce.bounce(ball, wall);
		}else if(wall instanceof GameWall){
			m_wallBounce.bounce(ball, wall);
		}
	}
	public void setSliderBounceBehaviour(BounceBehaviour b) {
		m_sliderBounce = b;
	}
}
